package com.pig4cloud.mall.product.controller;

import com.pig4cloud.mall.product.entity.CategoryBrandRelation;
import com.pig4cloud.mall.product.service.CategoryBrandRelationService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 品牌分类关联
 *
 * @author fangyu
 * @date 2020-11-25 14:58:43
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/categorybrandrelation")
@Api(value = "categorybrandrelation", tags = "品牌分类关联管理")
public class CategoryBrandRelationController {

    private final  CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 通过品牌id查询品牌分类关联
     * @param brandId 品牌id
     * @return R
     */
    @ApiOperation(value = "通过品牌id查询", notes = "通过品牌id查询")
    @GetMapping
//    @PreAuthorize("@pms.hasPermission('product_categorybrandrelation_get')")
    public R getById(@RequestParam Long brandId) {
        return R.ok(categoryBrandRelationService.getByBrandId(brandId));
    }

    /**
     * 新增品牌分类关联
     * @param categoryBrandRelation 品牌分类关联
     * @return R
     */
    @ApiOperation(value = "新增品牌分类关联", notes = "新增品牌分类关联")
    @SysLog("新增品牌分类关联")
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('product_categorybrandrelation_add')")
    public R save(@RequestBody CategoryBrandRelation categoryBrandRelation) {
        return categoryBrandRelationService.saveDetail(categoryBrandRelation);
    }

    /**
     * 通过id删除品牌分类关联
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除品牌分类关联", notes = "通过id删除品牌分类关联")
    @SysLog("通过id删除品牌分类关联")
    @DeleteMapping("/{id}")
//    @PreAuthorize("@pms.hasPermission('product_categorybrandrelation_del')")
    public R removeById(@PathVariable Long id) {
        return R.ok(categoryBrandRelationService.removeById(id));
    }

}
